/*
 * <one line to give the program's name and a brief idea of what it does.>
 * Copyright (C) 2019
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef ARENA_H
#define ARENA_H

#include "commondata.hpp"

class ShipDrone;
class ShipAI;
class ShipPlayer;

/**
 * \class Arena
 * Class for arena simulation: AI ship vs Player ships
 */
class Arena {
public:
	/**
	 * Constructor
	 * \param[in] data player data
	 */
	Arena(const PlayerData * data);
	Arena(const Arena & other) = delete;
	~Arena();

	/**
	 * Calculate bonuses, damage, hp and other params for each ship from player data.
	 * This function must be called before run simulation or result can be incorrect!
	 */
	void prepare();

	/**
	 * Simulate arena fight
	 */
	bool run();
private:
	/**
	 * Calculate one turn of fight
	 */
	void turn(ShipData *attacker, ShipData *victim);

	const PlayerData * m_Data;								/**<  pointer to player data. */

	ShipPlayer * m_ShipLeft = nullptr;						/**<  left ship */
	ShipPlayer * m_ShipMiddle = nullptr;					/**<  middle ship */
	ShipPlayer * m_ShipRight = nullptr;						/**<  right ship */
	ShipAI * m_ShipAI = nullptr;							/**<  ai ship */
	ShipDrone * m_Drones[5];								/**<  ship drones */

	// some helper functions

	/**
	 * \brief calculate gcd for a and b
	 * \param[in] a unsigned integer
	 * \param[in] b unsigned integer
	 * \return gcd
	 */
	uint32_t gcd(uint32_t a, uint32_t b);

	/**
	 * \brief calculate lcd for a and b
	 * \param[in] a unsigned integer
	 * \param[in] b unsigned integer
	 * \return lcd
	 */
	uint64_t lcd(const uint32_t & a, const uint32_t & b);

	/**
	 * \brief calculate lcd for few integers
	 * \param[in] a unsigned integer
	 * \param[in] b unsigned integer
	 * \param[in] c unsigned integer
	 * \param[in] d unsigned integer
	 * \return lcd
	 */
	uint64_t lcd(const uint32_t & a, const uint32_t & b, const uint32_t & c, const uint32_t & d);
};

#endif // ARENA_H
